Imports DotNetNuke
Imports DotNetNuke.Common.Global
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection

Namespace CEL.Modules.CELLibrary
    Partial Class AddBook
        Inherits Entities.Modules.PortalModuleBase

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If IsPostBack = True Then Exit Sub
            Call LocalizeSetting()
            If Request.QueryString("LibraryID") <> "" Then Call loadLibraryData(Val(Request.QueryString("LibraryID")))
        End Sub
        Public Sub loadLibraryData(ByVal LibraryID As Integer)
            Dim objLibraryCon As New CELLibraryController
            Dim dtTable As DataTable = objLibraryCon.getLibraryByID(LibraryID)
            If dtTable.Rows.Count > 0 Then
                If Not IsDBNull(dtTable.Rows(0)("Author")) Then Me.txtAuthor.Text = dtTable.Rows(0)("Author")
                'If Not IsDBNull(dtTable.Rows(0)("")) Then Me.lblCurrentlyBorrowed.Text = dtTable.Rows(0)("CurrentlyBorrowed")
                If Not IsDBNull(dtTable.Rows(0)("ISBN")) Then Me.txtISB.Text = dtTable.Rows(0)("ISBN")
                '   If Not IsDBNull(dtTable.Rows(0)("Owner")) Then Me.txtOwner.Text = dtTable.Rows(0)("Owner")
                If Not IsDBNull(dtTable.Rows(0)("PublishDate")) Then Me.txtPublishDate.Text = dtTable.Rows(0)("PublishDate")
                If Not IsDBNull(dtTable.Rows(0)("Publisher")) Then Me.txtPublisher.Text = dtTable.Rows(0)("Publisher")
                If Not IsDBNull(dtTable.Rows(0)("Title")) Then Me.txtTitle.Text = dtTable.Rows(0)("Title")

                If Not IsDBNull(dtTable.Rows(0)("Media")) Then cboMedia.Items.FindByValue(dtTable.Rows(0)("Media")).Selected = True
            End If
        End Sub
        Public Sub LocalizeSetting()
            Me.lblMedia.Text = DotNetNuke.Services.Localization.Localization.GetString("lblMedia", Me.LocalResourceFile)
            Me.lblAuthorTitle.Text = DotNetNuke.Services.Localization.Localization.GetString("lblAuthorTitle", Me.LocalResourceFile)
            Me.lblTitle.Text = DotNetNuke.Services.Localization.Localization.GetString("lblTitle", Me.LocalResourceFile)
            Me.lblISBTitle.Text = DotNetNuke.Services.Localization.Localization.GetString("lblISBTitle", Me.LocalResourceFile)
            'Me.lblOwnerTitle.Text = DotNetNuke.Services.Localization.Localization.GetString("lblOwnerTitle", Me.LocalResourceFile)
            Me.lblPublishDateTitle.Text = DotNetNuke.Services.Localization.Localization.GetString("lblPublishDateTitle", Me.LocalResourceFile)
            Me.lblPublisherTitle.Text = DotNetNuke.Services.Localization.Localization.GetString("lblPublisherTitle", Me.LocalResourceFile)
            Me.lnkBack.Text = DotNetNuke.Services.Localization.Localization.GetString("lnkBack", Me.LocalResourceFile)
            Me.lnkSave.Text = DotNetNuke.Services.Localization.Localization.GetString("lnkSave", Me.LocalResourceFile)
        End Sub

        Protected Sub lnkBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBack.Click
            Response.Redirect(EditUrl("ManageBooks"), True)
        End Sub

        Protected Sub lnkSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSave.Click
            Dim objLibraryCon As New CELLibraryController
            If Request.QueryString("LibraryID") <> "" Then
                objLibraryCon.UpdateLibrary(Me.txtTitle.Text, Me.txtISB.Text, Me.txtAuthor.Text, Me.txtPublisher.Text, Me.txtPublishDate.Text, Me.txtOwner.Text, Val(Request.QueryString("LibraryID")), Me.cboMedia.SelectedItem.Value)
            Else
                objLibraryCon.AddBook(Me.txtTitle.Text, Me.txtISB.Text, Me.txtAuthor.Text, Me.txtPublisher.Text, Me.txtPublishDate.Text, Me.txtOwner.Text, ModuleId, Me.cboMedia.SelectedItem.Value)
            End If

            Response.Redirect(EditUrl("ManageBooks"), True)
        End Sub
    End Class
End Namespace